#pragma once
#include "MSTCOSSDK.h"
#include "TPoint.h"
#include "IUpdate.h"
#include "Island.h"
#include "ICommand.h"

class StopCommand;

class Fatworm : public IUpdate
{
public:
	const static int IDLE = 0, TAKE_ISLAND = 1, ATTACK = 2, TRACKING = 3,
		SEQ_MOV = 4, HOLD = 5;
	const static int DIS_OFFSET = 50, RUSH_DIS = 50;
	const static int CIRCLE_ATTACK = 0, RUSH_ATTACK = 1, RUSH = 2;
	int team;
	float health;
	float cd[2];
	float speed;
	TPoint dir;
	bool isBlocked;
	bool isMoving;
	bool isRotating;
	TPoint pos;
	float r;
	TPoint axisSpeed;

	bool dead;
	TPoint moveTarget;
	bool updatedMov;
	int islandTarget;
	int attackTarget;
	int attackIdx;
	int attackStyle;
	bool updatedAtt;
	bool aimed;
	bool updatedRot;
	float rotAngel;
	float tarAngel;
	vector<Fatworm> *ours;
	vector<Fatworm> enemies;
	vector<Island> islands;
	int curCommand;
	float keepDis;
	int bakCommand;
	TPoint bakMoveTarget;
	bool stopMov;
	bool stopRot;
	bool justMov;
	int groupID;
	vector<ICommand*> movSequence;
	bool nextSeq;
	bool onPosition;
	float totallyStopSince;

	
private:
	static vector<Fatworm> emptyFatorm;
	static vector<Island> emptyIsland;
	int blockCount;
public:
	Fatworm(ShipInfo x);
	~Fatworm(void);
	virtual void update(ShipInfo x);
	void updateInfo(void);

	void takeIsland(int x);
	void meetAlliance(int idx);
	void rush(void);
	void rushAttack(void);
	void circleAttack(void);
	void attack(int x, int style=CIRCLE_ATTACK);
	void tracking(void);
	void hold(void);
	void hold(TPoint x);
	void cancelCommand(void);

	void regularCheck(void);

	void act(OSInterface* const system);

	//public for debug, should in private
	void moveToPoint( TPoint t );
	void setRotation(float r);

	friend StopCommand;

private:
	void meetNearestAlli(void);
	int outOfRange( void );
	void setAttackTarget(int x);
	void copyCommand( const Fatworm& ship );
	void checkBlock( void );
	bool willBlock( TPoint x );
	TPoint avoidBlock(TPoint x, bool seqMov = true);
};
